<?php
namespace app\frontend\controller;
use think\Db;
use think\captcha\Captcha;
use \think\Validate;
use think\Controller;

class Login extends Controller
{
    public function index()
    {
    	return view('./index/login');
    }
    public function check()
    {
    	session_start();
		$user_phone = input('post.phone','','strip_tags');
		$user_pwd = input('password');
		$user_mpwd=md5($user_pwd);
		$verify=input('verify');

		if(empty($verify))
            {
            	$this->error("验证码不能为空");
            }
        else if(!captcha_check($verify))
            {
            	$this->error("验证码错误");
            }
		
		$ret = db('user')->where("user_phone ='{$user_phone}' and user_pwd ='{$user_mpwd}'")->find();
		if($ret == false){

			$this->error("账号不匹配或密码不匹配");
		}
		
		session('user_id',$ret['user_id']);
		session('user_name',$ret['user_phone']);
		session('user_name',$ret['user_name']);
		session('user_pwd',$ret['user_pwd']);
		

		$this->success("登录成功",url('/frontend/index/index'));
	}

	public function Logout(){
            session(null);
            return $this->success('退出成功',url('/frontend/index/index'));
        }

}